package com.digitalchina.lxnsy.viewholder;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.TechnologyVO;
import com.digitalchina.lxnsy.toolkit.DateStyle;
import com.digitalchina.lxnsy.toolkit.DateUtil;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：白彦东
 * 创建时间：2016/12/28 18:10
 * 修改备注：
 * ================================================
 */

public class TechnologyHolder extends BaseViewHolder<TechnologyVO> {

    private TextView tvQuestion;
    private TextView tvAnswerContent;
    private TextView tvWhoAnswered;
    private TextView tvPraise;
    private TextView tvAnswerDate;
    private SimpleDraweeView ivAnswerImage;


    public TechnologyHolder(ViewGroup parent) {
        super(parent, R.layout.item_technology_list);
        tvQuestion = $(R.id.technology_question);
        ivAnswerImage = $(R.id.technology_iv_answered_image);
        tvAnswerContent = $(R.id.technology_answered_content);
        tvWhoAnswered = $(R.id.technology_who_answered);
        tvPraise = $(R.id.technology_tv_praise);
        tvAnswerDate = $(R.id.technology_tv_answer_date);
    }

    @Override
    public void setData(TechnologyVO data) {
        super.setData(data);
        if (data == null)
            return;
        if (data.getQuestion() != null) {
            tvQuestion.setText(data.getQuestion().getTitle());
        }
        if (data.getPerson() != null) {
            tvWhoAnswered.setText(data.getPerson().getNiceName() != null ? data.getPerson().getNiceName() : data.getPerson().getUserName());
        }
        if (StringUtil.isStrEmpty(data.getFirstPic())) {
            ivAnswerImage.setVisibility(View.GONE);
        } else {
            ivAnswerImage.setVisibility(View.VISIBLE);
            FrescoUtil.showImageNoSize(data.getFirstPic(), ivAnswerImage);
        }
        tvAnswerContent.setText(data.getWordContent() != null ? data.getWordContent().replace("\n","") : "");
        tvPraise.setText(String.format("%s赞同", data.getPraiseCount()));
        tvAnswerDate.setText(DateUtil.StringToString(data.getCreateAt(), DateStyle.YYYY_MM_DD_EN));
    }

}
